<?php
/*
 * Created on 2012-3-2
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 @header("Content-Type:text/html;charset=utf-8");
 include("../../nncms_manager_inc.php");
include $nncms_config_path. "nn_cms_manager/controls/nncms_controls_check_login.php";
//导入语言包
 if (isset($_SESSION["language_dir"])){
 	$language_dir=$_SESSION["language_dir"];
 }
include $nncms_config_path. "nn_cms_manager/languages/". $language_dir. "/language.php";
require_once $nncms_db_path. "nns_log".DIRECTORY_SEPARATOR . "nns_db_op_log_class.php";
$log_inst=new nns_db_op_log_class();

 $action=$_POST["action"];
 $nns_id=$_POST["nns_id"];



 //加载多语言
include_once($nncms_config_path.'nn_cms_config/nn_cms_global.php');
include_once($nncms_config_path.'nn_cms_manager/nncms_mlang.php');

 //获取权限检查类
include $nncms_db_path. "nns_pri/nns_db_pri_class.php";
$checkpri=new nns_db_pri_class();
$pri_bool=false;
if (!empty($action)){
	switch($action){
		case "edit":
		$action_str = '修改SP';
		$pri_bool=$checkpri->nns_db_pri_check($_SESSION["nns_role_pris"],"136002");
		break;
		case "add":
		$action_str= '添加SP';
		$pri_bool=$checkpri->nns_db_pri_check($_SESSION["nns_role_pris"],"136003");
		break;
		case "delete":
		$action_str= '删除SP';
		$pri_bool=$checkpri->nns_db_pri_check($_SESSION["nns_role_pris"],"136004");
		break;
		default:
		break;
	}
}
unset($checkpri);
if (!$pri_bool) {	
	Header("Location: ../nncms_content_wrong.php");
}else{

	include_once dirname(dirname(dirname(dirname(__FILE__)))).'/mgtv/models/sp_model.php';
	switch($action){
		case "edit":
		$sp_info=array(
		'nns_id' =>  $_POST['nns_id'],
		'nns_name' =>  $_POST['nns_name'],
		'nns_telphone' =>  isset($_POST['nns_telphone']) ? $_POST['nns_telphone'] :null,
		'nns_email' =>  isset($_POST['nns_email']) ? $_POST['nns_email'] :null,
		'nns_contact' =>  isset($_POST['nns_contact']) ? $_POST['nns_contact'] :null,
		'nns_rule' =>  isset($_POST['nns_rule']) ? $_POST['nns_rule'] :null,
		);	
		
		
		$result=   sp_model::update_sp($sp_info);//$partner_inst->nns_db_partner_modify($nns_id,$nns_partner_name,0,$nns_partner_desc,$nns_partner_contact,$nns_partner_phone,$nns_partner_email,$nns_partner_addr);
		if ($result["ret"]!=0){
			echo "<script>alert('". $action_str. cms_get_lang('fault'). "');</script>";
		}else{
			$log_inst->nns_db_op_log_add($_SESSION["nns_mgr_id"],$action,$_SESSION["nns_mgr_name"].$action_str.":".$nns_partner_name,$_SESSION["nns_manager_type"],$_SESSION["nns_org_id"]);
			echo "<script>alert('". $action_str. cms_get_lang('success'). "');</script>";
		}
		break;
		case "add":
		$b_exists = sp_model::exists_sp($_POST['nns_id']);
		if($b_exists){
			echo "<script>alert('ID已经存在');</script>";
		}else{
			$sp_info=array(
			'nns_id' =>  $_POST['nns_id'],
			'nns_name' =>  $_POST['nns_name'],
			'nns_telphone' =>  isset($_POST['nns_telphone']) ? $_POST['nns_telphone'] :null,
			'nns_email' =>  isset($_POST['nns_email']) ? $_POST['nns_email'] :null,
			'nns_contact' =>  isset($_POST['nns_contact']) ? $_POST['nns_contact'] :null,
			'nns_rule' =>  isset($_POST['nns_rule']) ? $_POST['nns_rule'] :null,
			);		
			$result=  sp_model::add_sp($sp_info); //$partner_inst->nns_db_partner_add($nns_id, $nns_partner_name,0,$nns_partner_desc,$nns_partner_contact,$nns_partner_phone,$nns_partner_email,$nns_partner_addr);
			if ($result["ret"]!=0){
				echo "<script>alert('". $action_str. cms_get_lang('fault'). "');</script>";
			}else{
				$log_inst->nns_db_op_log_add($_SESSION["nns_mgr_id"],$action,$_SESSION["nns_mgr_name"].$action_str.":".$nns_partner_name,$_SESSION["nns_manager_type"],$_SESSION["nns_org_id"]);
				echo "<script>alert('". $action_str. cms_get_lang('success'). "');</script>";
			}			
		}

		break;
		case "delete":
		$delete_bool=true;
	//	$role_inst->
			$nns_ids=explode(",",$nns_id);
			$delete_bool = sp_model::batch_delete_sp($nns_ids);
		if (!$delete_bool){
			echo "<script>alert('". $action_str. cms_get_lang('fault'). "');</script>";
		}else{
			$log_inst->nns_db_op_log_add($_SESSION["nns_mgr_id"],$action,$_SESSION["nns_mgr_name"].$action_str.":".$nns_names,$_SESSION["nns_manager_type"],$_SESSION["nns_org_id"]);
			echo "<script>alert('". $action_str. cms_get_lang('success'). "');</script>";
		}
		break;
		default:

		break;
	}
	$partner_inst=null;
	//var_dump($result);
	$log_inst=null;
	echo "<script>self.location='nncms_content_sp_list.php';</script>";
}
?>
